package com.Pure;

import android.graphics.Color;

import android.widget.Toast;
import android.graphics.Typeface;
import android.view.KeyEvent;
import android.view.MotionEvent;
import com.e3roid.E3Activity;
import com.e3roid.E3Engine;
import com.e3roid.E3Scene;
import com.e3roid.drawable.Menu;
import com.e3roid.drawable.Shape;
import com.e3roid.drawable.Sprite;
import com.e3roid.drawable.modifier.*;

import com.e3roid.drawable.modifier.function.*;
import com.e3roid.drawable.sprite.TextSprite;
import com.e3roid.drawable.texture.Texture;
import com.e3roid.drawable.texture.AssetTexture;
import com.e3roid.event.ShapeEventListener;
import com.e3roid.script.javascript.JavaScriptEngine;

public class PureMain extends E3Activity {

    private final static int WIDTH  = 320;
    private final static int HEIGHT = 480;

	 public static PureGameObject currentObj = null;
	 private static int currentLevel = 0;
	
    private static PureMain instance;
    PureGameFactory factory;
    PureMenu menu;
    PureLevel level;
    
    public static PureMain getInstance()
    {
    	return instance;
    }
    @Override
    public E3Engine onLoadEngine() {
    		instance = this;
    		factory = new PureGameFactory(this);
    		
            E3Engine engine = new E3Engine(this, WIDTH, HEIGHT);
            engine.requestFullScreen();
            engine.requestPortrait();
            
            return engine;
    }

    @Override
    public E3Scene onLoadScene() {
    	
		
    		level = PureLevelLoader.loadFromFile("level01.js", this);
    		
            menu = new PureMenu(this,level);
            level.addMenu(menu);
            level.showMenu();
            level.addEventListener(this);
            return level;
    }

    @Override
    public void onLoadResources() {
    	factory.loadResource();
    }

    @Override
	public boolean onKeyDown(E3Scene scene, int keyCode, KeyEvent event) {
    	
    	boolean returnBoolean = true;
    	returnBoolean |= menu.onKeyDown(scene, keyCode, event);
    	returnBoolean |= level.onKeyDown(scene, keyCode, event);
    	
    	//changeLevel("level02.js");
    	if(level.getVempireCount() == 0)
		{
    		currentLevel = (currentLevel + 1) % 4;
    		if(currentLevel < 10)
    			changeLevel("level0" + Integer.toString(currentLevel + 1)+ ".js");
		}
	   	
		return super.onKeyDown(scene, keyCode, event) || returnBoolean;
		
	}
    
	@Override
	public boolean onSceneTouchEvent(E3Scene scene, MotionEvent motionEvent) {
		if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
			
			
			
		}
		
		return false;
	}
	
    public PureLevel changeLevel(String filename)
    {
    	
    	PureLevelLoader.loadAgain(filename,level, this);
    	
        
        
    	return level;
    }
    
   
}
